import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useTitleStore = defineStore(
  'useTitleStore',
  () => {
    const titleInfo = ref({
      menuItems: []
    })
    const updataTitInfo = (data) => {
      const itemIndex = titleInfo.value.menuItems.findIndex(
        (item) => item.title === data.value.title
      )
      if (itemIndex !== -1) {
        return
      } else {
        titleInfo.value.menuItems.push(data.value)
      }
    }
    const removeTitinfo = (data) => {
      //移除
      const itemIndex = titleInfo.value.menuItems.findIndex(
        (item) => item.title === data.title
      )
      titleInfo.value.menuItems.splice(itemIndex, 1)
    }
    return {
      titleInfo,
      updataTitInfo,
      removeTitinfo
    }
  },
  {
    persist: true
  }
)
